package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import easier.baidu.tts.BaiduTTSManager;

/**
 * https://console.bce.baidu.com/ai/#/ai/speech/overview/index
 */
public class MainActivity116 extends AppCompatActivity {

    private EditText edit;
    private Button speak;

    private BaiduTTSManager mBaiduTTSManager;

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity116.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main116 );
        initView();
    }

    private void initView() {

        String appId = "39272424";
        String appKey = "a0rIfTQKSDOxVuDj8XKjLT8K";
        String secretKey = "vmulgGjij9qd8lzpzFGNLgyqweVg8WGR";

        mBaiduTTSManager = new BaiduTTSManager( this, appId, appKey, secretKey );

        edit = (EditText) findViewById( R.id.edit );
        speak = (Button) findViewById( R.id.speak );

        speak.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                mBaiduTTSManager.speak( edit.getText() );
            }
        } );
    }
}